#include<iostream>
#include<string>
#include<queue>
#define Maxsize 100
using namespace std;
typedef struct node{
	char data;
	struct node *lchild;
	struct node *rchild;
}BTNode;
typedef BTNode *BTree;
void createBTree(BTree &BT,string str);
void LevelOrder(BTree BT);
int main()
{
	string str;
	BTree BT;
	cin>>str;
	createBTree(BT,str);
	if(BT!=NULL) 
	LevelOrder(BT);
	else
	cout<<"NULL"; 
	return 0;
}
void createBTree(BTree &BT,string str)
{
	int i=1;
	BTree T;
	queue<BTree> Q;
	if(str[1]=='#'||str[1]=='\0')
	BT=NULL;
	else 
	{
		BT=new BTNode;
		BT->data=str[i];
		BT->lchild=BT->rchild=NULL;
		Q.push(BT); 
	}
	while(!Q.empty() )
	{
		T=Q.front();
		Q.pop();
		i++;
		if(str[i]=='\0')
		break;
		if(str[i]=='#')
		T->lchild=NULL;
		else
		{
			T->lchild=new BTNode;
			T->lchild->data =str[i];
			T->lchild->lchild=T->lchild->rchild=NULL;
			Q.push(T->lchild);
		}
		i++;
		if(str[i]=='\0')
		break;
		if(str[i]=='#')
		T->rchild=NULL;
		else
		{
			T->rchild=new BTNode;
			T->rchild->data =str[i];
			T->rchild->lchild=T->rchild->rchild=NULL;
			Q.push(T->rchild);
		}
	}
	
}
void LevelOrder(BTree BT)
{
	BTree p;
	BTree qu[Maxsize];
	int front,rear,j=-1;
	front=rear=-1;
	rear++; 
	qu[rear]=BT;
	while(front!=rear)
	{
		front=(front+1)%Maxsize;
		p=qu[front];
		j++;
		if(j!=0)
		cout<<" ";
		cout<<p->data;
		if(p->lchild!=NULL)
		{
			rear=(rear+1)%Maxsize;
			qu[rear]=p->lchild;
		}
		if(p->rchild!=NULL)
		{
			rear=(rear+1)%Maxsize;
			qu[rear]=p->rchild;
		}
	}
}
